from django.db import models

# Create your models here.


set_choice = (
    (0, '女姓'),
    (1, '男姓'),
)


class Department(models.Model):
    name = models.CharField("部门名称", max_length=20)

    class Meta:
        db_table = "department"


class Role(models.Model):
    role_name = models.CharField("角色名称", max_length=20, null=True)
    people_num = models.FloatField("人头系数", null=True)
    department = models.ForeignKey(to=Department, to_field='id', on_delete=models.CASCADE, null=True)

    class Meta:
        db_table = "role"


class User(models.Model):
    number = models.CharField('编号', max_length=30, null=True)
    name = models.CharField("姓名", max_length=20)
    sex = models.IntegerField("性别", choices=set_choice, default=0)
    ID_type = models.CharField('证件类型', max_length=10)
    user_ID = models.CharField("证件号码", max_length=18, unique=True)
    birth_data = models.CharField("出生日期", max_length=30, null=True)
    phone = models.CharField("手机号", max_length=11, unique=True)  #
    password = models.CharField("密码", max_length=200, default="123456")
    email = models.EmailField("邮箱", max_length=30, unique=True)
    education = models.CharField("学历", max_length=20, null=True)
    job = models.CharField("岗位", max_length=20, null=True)
    basic_wage = models.FloatField("基础工资", null=True)
    entry_time = models.CharField("入职日期", max_length=30, null=True)
    dimission_time = models.CharField("离职日期", max_length=30, null=True)
    salary_start = models.CharField("工资始发", max_length=30, null=True)
    regular_time = models.CharField("转正日期", max_length=30, default="实习", null=True)
    bank_account = models.CharField("银行账户名称", max_length=10, null=True)
    bank_name = models.CharField("银行名称", max_length=20, null=True)
    bank_ID = models.CharField("银行账号", max_length=20, null=True)
    social_state = models.CharField("社保状态", max_length=20, null=True)
    social_cardinal = models.CharField("社保缴纳基数", max_length=10, null=True)
    provide_insurance = models.FloatField("养老保险", null=True)
    medical_insurance = models.FloatField("医疗保险", null=True)
    unemployment_insurance = models.FloatField('失业保险', null=True)
    accumulation = models.FloatField("公积金", null=True)
    token = models.CharField("token", max_length=500, null=True)
    token_end = models.IntegerField("token过期时间", null=True)
    role = models.ForeignKey(to=Role, to_field='id', on_delete=models.CASCADE, null=True)
    admission = models.FloatField("工会费", default=0)
    salarys = models.FloatField("工资比率", default=0.8)
    college = models.ForeignKey(to='Department', to_field="id", on_delete=models.CASCADE, null=True)

    class Meta:
        db_table = "user"


# 主题
class Salary_theme(models.Model):
    name = models.CharField("主题名称", max_length=200)
    attendance = models.CharField("考勤月份", max_length=30)
    salary_start = models.CharField("工资始发月", max_length=30)
    grant_num = models.IntegerField("发放人数", default=0)
    create_people = models.CharField("创建人", max_length=30)
    total_money = models.IntegerField("总金额", default=0)
    department = models.ForeignKey(to=Department, to_field="id", on_delete=models.CASCADE, null=True)  # 关联部门

    class Meta:
        db_table = "salary_theme"


# 工资单
class Salary_college(models.Model):
    wage_ratio = models.CharField("工资比率", max_length=6, null=True)
    should_attend = models.IntegerField("应出勤", default=0)
    practical_attend = models.IntegerField("实际出勤", default=0)
    reckon_day = models.IntegerField("计入天数", default=0)
    seniority = models.FloatField("工龄工资", default=0)
    class_fee = models.FloatField("课时费", default=0)  # 讲师特有
    guide_benefits = models.FloatField("导员津贴", default=0)  # 导员特有
    college_num = models.FloatField("学院人头费", default=0)  # 学院人员特有 除讲师
    bonus = models.FloatField("奖金", default=0)  # 学院人员特有
    subsidy = models.FloatField("补贴", default=0)  # 职能部门特有
    social_security = models.FloatField("单位社保", default=0)
    social_accum = models.FloatField("单位公积金", default=0)
    expenditure = models.FloatField("公司支出合计", default=0)
    absenteeism = models.FloatField("扣缺勤工资", default=0)
    insurance_charges = models.FloatField("扣单位承担社会保险费", default=0)
    abnormal = models.FloatField("异常扣款及迟到、转正差额", default=0)
    should_salary = models.FloatField("应发工资", default=0)
    individual = models.FloatField("个税", default=0)
    admission = models.FloatField("工会费", default=0)
    net_payroll = models.FloatField("实发金额", default=0)
    salary_state = models.BooleanField("工资状态", null=True)  # True已审核    False未审核
    grant_time = models.CharField("发放日期", max_length=30, null=True)
    # user = models.ForeignKey(to='User', on_delete=models.CASCADE, to_field='id', null=True)  # 关联用户id
    phone = models.ForeignKey(to='User', to_field='phone', on_delete=models.CASCADE, null=True)    # 关联用户手机号
    salary_theme = models.ForeignKey(to='Salary_theme', on_delete=models.CASCADE, to_field='id', null=True)  # 关联工资主题id

    class Meta:
        db_table = "salary_college"
